// 数据库服务工厂
const SQLiteService = require('./sqlite-service');
const path = require('path');

class DatabaseServiceFactory {
  static createService(type, config) {
    switch (type.toLowerCase()) {
      case 'sqlite':
        return new SQLiteService(config);
      case 'mysql':
        // 未来可以添加MySQL支持
        throw new Error('MySQL support not implemented yet');
      case 'postgresql':
        // 未来可以添加PostgreSQL支持
        throw new Error('PostgreSQL support not implemented yet');
      default:
        throw new Error(`Unsupported database type: ${type}`);
    }
  }
}

// 创建默认的SQLite服务实例
const defaultConfig = {
  dbPath: path.join(__dirname, '../server/warehouse.db')  // 使用绝对路径
};

const defaultDatabaseService = DatabaseServiceFactory.createService('sqlite', defaultConfig);

module.exports = {
  DatabaseServiceFactory,
  defaultDatabaseService
};